package com.basics.organization.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.basics.common.utils.StringUtils;
import com.basics.organization.entity.CyOrganizationGroup;
import com.basics.organization.mapper.CyOrganizationGroupMapper;
import com.basics.organization.service.CyOrganizationGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 组织分组 服务实现类
 * </p>
 *
 * @author WangWei
 * @since 2025-03-09
 */
@Service
public class CyOrganizationGroupServiceImpl extends ServiceImpl<CyOrganizationGroupMapper, CyOrganizationGroup> implements CyOrganizationGroupService {

    @Override
    public String getByGroupIds(String groupIds){
        if(StringUtils.isEmpty(groupIds)){
            return null;
        }
        List<CyOrganizationGroup> groupList = list(new QueryWrapper<CyOrganizationGroup>().eq("id", Arrays.asList(groupIds.split(","))));
        if(CollectionUtils.isNotEmpty(groupList)){
            return groupList.stream().map(CyOrganizationGroup::getGroupName).reduce((a,b)->a+","+b).get();
        }
        return null;
    }

    @Override
    public CyOrganizationGroup getDefaultGroup(Long organizationId){
        return getOne(new QueryWrapper<CyOrganizationGroup>().eq("organization_id",organizationId).eq("default_flag",1));
    }
}
